package com.starnet.studentmanagement.controller;


import com.starnet.studentmanagement.entity.CourseSelection;
import com.starnet.studentmanagement.service.CourseSelectionService;
import com.starnet.studentmanagement.service.CoursesService;
import com.starnet.studentmanagement.vo.PageResult;
import com.starnet.studentmanagement.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sangeng
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/courseSelection")
public class CourseSelectionController {
    @Autowired
    CourseSelectionService courseSelectionService;
    @PostMapping
    public Result addNewGrade(@RequestBody @Valid CourseSelection courseSelection){
        return courseSelectionService.addNewGrade(courseSelection);
    }
    @PutMapping
    public Result updateGrade(@RequestBody @Valid CourseSelection courseSelection){
        return courseSelectionService.updateGrade(courseSelection);
    }

    @DeleteMapping("/{id}")
    public Result deleteGrade(@PathVariable("id")Integer id){
        return courseSelectionService.deleteGradeById(id);
    }

    @GetMapping
    public PageResult listAll(@RequestParam("page")Integer page, @RequestParam(value = "pageSize",required = false)Integer pageSize, @RequestParam(value = "cid",required = false)String cid){
        return courseSelectionService.listAll(page,pageSize,cid);
    }
    @GetMapping("/pass/{cid}")
    public Result getPassRate(@PathVariable("cid")String cid){
        return courseSelectionService.getPassRate(cid);
    }

}
